package x.ovo.wechat.bot.plugin;

import lombok.NonNull;
import x.ovo.wechat.bot.core.command.CommandExcutor;
import x.ovo.wechat.bot.core.entity.Contact;
import x.ovo.wechat.bot.core.event.EventListener;
import x.ovo.wechat.bot.core.event.MessageEvent;
import x.ovo.wechat.bot.core.message.TextMessage;
import x.ovo.wechat.bot.core.plugin.Plugin;

import java.util.Objects;

public class RestartPlugin extends Plugin {

    @Override
    public void onLoad() {
    }

    @Override
    public EventListener<?, ?> getEventListener() {
        return new EventListener<MessageEvent<TextMessage>, TextMessage>(this) {
            @Override
            public boolean support(@NonNull MessageEvent<TextMessage> event, TextMessage source) {
                Contact owner = this.plugin.getContext().getOwner();
                return source.getContent().equals("/restart") && Objects.equals(owner, source.getFrom());
            }

            @Override
            public boolean onEvent(@NonNull MessageEvent<TextMessage> event, TextMessage source) {
                System.exit(1);
                return true;
            }
        };
    }

    @Override
    public CommandExcutor getCommandExcutor() {
        return null;
    }
}
